﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MpSoft.Library.DAO.Customers;
using MpSoft.Library.DTO;
using MpSoft.Basic.Configuration;
namespace MpSoft.Library.BUSS.Customers
{
    #region  Poll
    public class PollBUSS
    {
        private const string POLL_ALL_KEY = "Mp.poll.all-{0}";
        private const string POLL_BY_ID_KEY = "Mp.poll.id-{0}";

        private static void RemoveCache()
        {
            MpCache.RemoveByPattern(POLL_ALL_KEY);
            MpCache.RemoveByPattern(POLL_BY_ID_KEY);
        }

        public static int Poll_Add(Poll obj)
        {
            var result = PollDAO.Poll_Add(obj);
            if (result > 0)
                RemoveCache();
            return result;
        }
        public static int Poll_Update(Poll obj)
        {
            var result = PollDAO.Poll_Update(obj);
            if (result > 0)
                RemoveCache();
            return result;
        }

        public static int Poll_Delete(int PollID)
        {
            var result = PollDAO.Poll_Delete(PollID);
            if (result > 0)
                RemoveCache();
            return result;
        }
        public static Poll Poll_ByID(int PollID)
        {
            var list = PollDAO.Poll_List(PollID, 0);
            if (list != null)
                return list.FirstOrDefault();
            return null;
        }
        public static List<Poll> Poll_ByPollID(int PollID, int Published)
        {
            return Poll_List(PollID, Published);
        }

        public static List<Poll> Poll_List()
        {
            return PollDAO.Poll_List(-1, -1);
        }

        public static List<Poll> Poll_List(int PollID, int Published)
        {
            return PollDAO.Poll_List(PollID, Published);
        }
    }
    #endregion
}
